package m202406.d10;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/10 12:08
 */
public class Q46 {
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        for (int num : nums) {
            list.add(num);
        }
        doPermute(0, list, res);
        return res;
    }

    private void doPermute(int start, List<Integer> nums, List<List<Integer>> res) {
        if (start == nums.size()) {
            res.add(new ArrayList<>(nums));
        }

        for (int i = start; i < nums.size(); i++) {
            Collections.swap(nums, start, i);
            doPermute(start + 1, nums, res);
            Collections.swap(nums, start, i);
        }
    }
}
